package com.ethink.order.manager;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @author default
 * @version 1.0.0
 * @ClassName Pub.java
 * @Description
 * @createTime 2022年11月16日 14:14:00
 */
@Component
public class PublicManager {

    /**
     * 毛利率计算
     * @return
     */
    public BigDecimal computeRate(BigDecimal param1,BigDecimal param2,int scale){
        if (param1 == null || param2 == null){
            return BigDecimal.ZERO;
        }
        return param1.subtract(param2).divide(param1,scale,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
    }
    public BigDecimal computeRate(BigDecimal param1,BigDecimal param2){
        return computeRate(param1,param2,4);
    }


    /**
     * 乘
     * @param param1
     * @param param2
     * @return
     */
    public BigDecimal mult(BigDecimal param1,BigDecimal param2){
        if (param1 == null || param2 == null){
            return BigDecimal.ZERO;
        }
        return param1.multiply(param2);
    }

    /**
     * 不含税计算
     */
    public BigDecimal noTaxCal(BigDecimal price,BigDecimal taxRate,BigDecimal discount){
        if (price == null || taxRate == null || discount == null){
            return BigDecimal.ZERO;
        }
        return price.divide(BigDecimal.ONE.add(taxRate.divide(new BigDecimal("100"))),6,BigDecimal.ROUND_HALF_UP).multiply(discount);
    }

}
